<template>
  <RkContainer :isAside="false"
    :isFooter="false">
    <template #header_left>
    </template>
    <template #header_right>
      <el-button @click="handleEdit"
        type="primary">修改</el-button>
      <el-button @click="handleRefresh">刷新缓存</el-button>
    </template>
    <template #main>
      <rk-center>
        <template #content>
          <rk-grid ref="sysParamsTableRef"
            boxConfig="radio"
            :title="route.meta.title"
            :dataUrl="'/sysParam/getSysParamList'"
            :columns="tableColumns"
            :params="queryParams"
            :radio-config="{ checkMethod: checkRadioMethod}"
            :pagerConfig="false">
            <template #toolbar_right>
              <el-input v-model="queryParams.keywords"
                style="width: 240px;"
                placeholder="请输入系统参数编码/名称"
                @input="handleSearch"
                clearable />
            </template>
          </rk-grid>
        </template>
      </rk-center>
    </template>
    <SysParamsDialog ref="sysParamsDialogRef"
      @confirm="handleSearch" />
  </RkContainer>
</template>

<script setup>
import { useRoute } from 'vue-router'
import { ElMessage } from 'element-plus'
import SysParamsDialog from './SysParamsDialog.vue'
import { useSystemApi } from '@/api/index';
const { refreshSysParamCache } = useSystemApi()

// 获取当前路由
const route = useRoute()
// 系统参数
const queryParams = reactive({
  keywords: ''
})
const sysParamsTableRef = ref('')
const sysParamsDialogRef = ref('')
const tableColumns = ref([
  { field: 'dCode', title: '系统参数编码', width: 250, align: 'left' },
  { field: 'dName', title: '系统参数名称', width: 250, align: 'left' },
  { field: 'dValue', title: '系统参数值', width: 250, align: 'left' },
  { field: 'paramValueset', title: '系统参数取值范围', width: 250, align: 'left' },
  { field: 'dDesc', title: '系统参数说明', width: 250, align: 'left' },
])
const checkRadioMethod = ({ row }) => {
  return !!(row.isEdit === 1)
}

// 查询
const handleSearch = () => {
  sysParamsTableRef.value.searchEvent()
}
// 修改
const handleEdit = () => {
  const selectRow = sysParamsTableRef.value.getRadioRecord()
  if (selectRow) {
    sysParamsDialogRef.value.handleOpen(selectRow)
  } else {
    ElMessage.warning('请选择一条数据！')
  }
}
/** 区划刷新 */
const handleRefresh = async () => {
  const result = await refreshSysParamCache({})
  const { data, code, msg } = result
  if (code === 200) {
    ElMessage({
      message: `刷新缓存成功！`,
      type: 'success',
    })
  } else {
    ElMessage({
      message: `刷新缓存失败！`,
      type: 'error',
    })
  }
}
</script>
<style lang="scss" scoped>
:deep(.el-container) {
  border-bottom: 0px !important;
}
</style>